const { NotFoundError } = require('../middleware/errorHandler');
const logger = require('../config/logger');

// 404处理中间件
const notFound = (req, res, next) => {
  // 记录404请求
  logger.warn('404 Not Found', {
    method: req.method,
    url: req.originalUrl,
    ip: req.ip,
    userAgent: req.get('User-Agent'),
    requestId: req.requestId,
    userId: req.user?.id
  });
  
  const error = new NotFoundError(`路由 ${req.method} ${req.originalUrl} 未找到`);
  next(error);
};

module.exports = notFound;